﻿using System;
using System.Collections.Generic;

namespace Chappie.Infrastructure.Cache
{
    /// <summary>
    /// 缓存接口
    /// </summary>
    public interface ICacheProvider
    {
        /// <summary>
        /// 添加永久缓存(有则添加,无则更新)
        /// </summary>
        /// <typeparam name="T">缓存值类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <param name="value">缓存值</param>
        /// <returns></returns>
        void Set<T>(string key, T value);

        /// <summary>
        /// 添加绝对过期缓存(有则添加,无则更新)
        /// </summary>
        /// <typeparam name="T">缓存值类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <param name="value">缓存值</param>
        /// <param name="expiresAt">缓存过期绝对时间点</param>
        /// <returns></returns>
        void Set<T>(string key, T value, DateTime expiresAt);

        /// <summary>
        /// 添加相对过期缓存(有则添加,无则更新)
        /// </summary>
        /// <typeparam name="T">缓存值类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <param name="value">缓存值</param>
        /// <param name="expiresIn">缓存过期相对过期时间</param>
        /// <returns></returns>
        void Set<T>(string key, T value, TimeSpan expiresIn);

        /// <summary>
        /// 批量添加同类型缓存
        /// </summary>
        /// <typeparam name="T">缓存值类型</typeparam>
        /// <param name="values">缓存值</param>
        void SetMulti<T>(IDictionary<string, T> values);

        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <typeparam name="T">缓存值类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <returns></returns>
        T Get<T>(string key);

        /// <summary>
        /// 批量获取同类型缓存
        /// </summary>
        /// <param name="keys">缓存键集合</param>
        /// <returns></returns>
        IDictionary<string, T> GetAll<T>(IEnumerable<string> keys);

        /// <summary>
        /// 移除缓存
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns></returns>
        void Remove(string key);

        /// <summary>
        /// 批量移除缓存
        /// </summary>
        /// <param name="keys">缓存键集合</param>
        void RemoveMulti(IEnumerable<string> keys);

        /// <summary>
        /// 判断缓存是否存在
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns>存在返回Ture,不存在返回Flase</returns>
        bool Exists(string key);

        /// <summary>
        /// 清空所有缓存对象
        /// </summary>
        void Flush();
    }
}